#ifndef BOOST__THREAD__DEFAULT_SCHEDULER_HPP
#  define BOOST__THREAD__DEFAULT_SCHEDULER_HPP

// Copyright (C) 2004-2009
// Alex Turbov, Igor Veresov
//
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#  include <boost/thread/details/lock_matrix.hpp>

#  include <boost/call_traits.hpp>
#  include <boost/fusion/include/at_c.hpp>
#  include <boost/fusion/include/vector.hpp>


namespace boost {

template <typename MatrixSpec>
struct default_scheduler
  : protected details::lock_matrix<
        typename MatrixSpec::type
      , typename MatrixSpec::matrix_type
      >
{
    typedef details::lock_matrix<
        typename MatrixSpec::type
      , typename MatrixSpec::matrix_type
      > matrix_type;

    typedef fusion::vector<typename matrix_type::lock_type> lock_params_type;
    typedef fusion::vector<typename matrix_type::lock_type> unlock_params_type;

    bool try_lock(typename call_traits<lock_params_type>::param_type p, int /* request_id */)
    {
        bool result = matrix_type::can_lock(fusion::at_c<0>(p));
        if (result) matrix_type::lock(fusion::at_c<0>(p));
        return result;
    }
    void unlock_(typename call_traits<unlock_params_type>::param_type p)
    {
        matrix_type::unlock_(fusion::at_c<0>(p));
    }
    //
    bool is_used() const
    {
        return matrix_type::is_locked();
    }
    /// unused by this policy
    int assign_request_id(typename call_traits<lock_params_type>::param_type /* p */)
    {
        return 0;
    }
    /// unused by this policy
    void unassign_request_id(typename call_traits<lock_params_type>::param_type /* p */, int /* request_id */)
    {}
};

}
#endif                                                     // #ifndef BOOST__THREAD__DEFAULT_SCHEDULER_HPP
